package com.api.qfengx;

import com.alibaba.fastjson.JSON;
import com.weaver.qfengx.DaoUtils;
import com.weaver.qfengx.NumberUtils;
import com.weaver.qfengx.entity.PageQuery;
import com.weaver.qfengx.entity.Result;
import org.bouncycastle.crypto.BufferedBlockCipher;
import org.bouncycastle.crypto.engines.AESFastEngine;
import org.bouncycastle.crypto.modes.CBCBlockCipher;
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.crypto.params.ParametersWithIV;
import org.bouncycastle.util.encoders.Hex;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

/**
 * @Description
 * @Author Qfengx <qffg1998@126.com>
 * @Date 2021-07-13 00:03:58
 */
@Path("/test")
public class DispatchTestApi {

    @GET
    @Path("/result")
    @Produces(MediaType.APPLICATION_JSON)
    public String Result() {
        return JSON.toJSONString(Result.ok());
    }

    @GET
    @Path("/type/list")
    @Produces(MediaType.APPLICATION_JSON)
    public String typeList(@Context HttpServletRequest request) {
        int page = NumberUtils.parseInt(request.getParameter("page"), 0);
        int limit = NumberUtils.parseInt(request.getParameter("limit"), 10);
        return JSON.toJSONString(Result.ok(DaoUtils.executePageMapList("select * from workflow_type", new PageQuery(page, limit))));
    }

    public static void main(String[] args) {
//        String content = "59e4c68751997c4615f9c04803ba176338a4a7bc8e0a626f6e238758f51966f19beb055f8897a37409b1a7e00219d513442d2a97b36d299fd57143923d6ee6783ce8ea1aa13329dc07de911db4aacd50b9d7058230cd24967144af11e3e2780083d906cca6d67606b978eb1d912e64cadd334a24fd62fef80c1ca31fa890b673610d6d72ade720f5a1bd4d5b9b7294527e600a6ca1d1cf2d4d5ad7fec6c2672906085163702b7a98ac1f742abed12aaaa2381050c2e5c77d941307611944d6baaee8e35d279b4b42d977ee68a681988f6576c86d7ffdf030f760e4de64eae60bcb62626c61b61dbd30c5e70f605ee57b7a50139253fae0531eb1f787ff593c6eefb2755016e0f86f7842aea23288600d08a3654a69256426f127caf0cede7caf335c5d323694c28d03094d80c191bca1acf8ae33dff6302f896fd0953cc553df4b87aec014c7725502f3b8f412178eba82601d248447811cc3b79f609bf5fa0ff1e6eeb5535b328a548650fb891a07979f69a9bd9ad42cc79c1153fcf7dbeb962ec528cd6b69af0367aef6965983c72b5d529dd88fd1690d7071888116e158b53a842bf9a5c26103894acc220c161e83fd5524f3fc7b7594e915fe6660a2a8afd3e69a27111d855fe88ed71aaeda525b0330b431417563c73e02828c7504679d079cc122abe10d86b1053fdde0b9663df97994b7563ee49d516e64af37c56b1c5fcb56d9ba11915616dcc0990318e0a762466902da4c5857296131f4ba52ea411bc4a624f16d68192181986221b21d68bb404eb4099701340ee54c078026f057cb3f571d923f5dbe974e2385b2168d3978a0c0578cc65b071dbf7bd06d926391612f1eaf661cd1f847cb4897f30a89144631e7272b635654172b7364f81dd439857910af4a8eb7f48a7d264beddc37c9b4cb127fb78f1835f11ffd26efa1267f8247d59815dcbbc1698b470585184a8d60509ce361626c22a3f654788fa2a7fe6bb24f673798cebadfd81a015fc9057b5ca3b09178cfc66ec6427d60e0b24e5223f104868423c1890fa20a9dceb71810fed2cdcb2003527f7e4d588515ee64e1adc842a92d61bae63b13a330e50aa94b755774d3a6680d29cc8ff70b75d41a6f3a70af116ec6b93487f76903bcdff8e022eeb01e3b49af03e565bcccb8276e009a3f20ed18bc2da9f821d5da18d8410a555dc12640826025b66801ab711158933ceaf2dd94be79263330f498d9bdbca423305a0ce1f55c62f8408822c23684245672166c53fefd53a9c4ad6a84c1f16c41a987932b9821884bbf4a87be08301518de1ba82181dbd108576080803531b3f206c020eb408bfb702bda65521aa9eb7a1f32d257af7238b882761bc68febcb9fa9d09c3dcd51739de47acb1252988aae85e7beb658dc8b74bc498e54a76e6870578c150cee114c3b806dbf2b3d854d52c6c3c14e253bc66e67b451a30207a62123c64511d8173477a6ec99cd3dbea8beaff5295c6fc56a97b6fee3963dcabf0b9f8f0e4f6b3593f70f5751d5b9fd3ccd6d271e30156ef11971db53338afe01d2150a1e28a36b111ee027e5edaae9ac4485ae697e22b9d14661579f6400e50452365952e779f3348f94740323a2d913adc84f97456cdaea5f4c4f3bb39027e29d68e11b10cb321c5ec4a2fbdcfd87f40f63765b499a63f8061845221ee091cc526e3606ff0de1bfcf89ff736a1c09619237f1907f7883510633465d3af001ab42f2a9532d7ffa4dc092f774ee12ffca6f42d2cb58bcd2f943764b5df0f3b0b0e792de3b7fd10118fd45ac84397fb88670dd75fbec074a29129cd74c85822471c2f3b98b64573df29a29db8ac86298db7d3a9f8e566268a9840892c8e2041b2f122b0244e35ecb17c56adcea510ecfc74a3722aefd0424aaf004c40a17925308b24b692d38affbdfa7d04024150c4ba500adde1c8701c83bf0a47d5c8931407819674ada178bc0e5062cbf6c4f4797168a0f14f35fe9df3577dd5506fce071eeda7e86d88f36f6c2be9cb26cf3333dd8e21891606039b821292022085ba8bb088a894513fb6f600ca23b14e1d73533a99490a088d1fd26d4b29ea6f14f4a949e2b74d71fa9ddfb111c32663e4a4f8d802e42cf320a68b85ff0201911f5d4fd616882c21e79cfcaa38f4cafac0cd92d08db304b869e5c9f4b14fe8135190dbc2e";
        String content = "9e9259345bbb2062514e057ea454ac37302aa6fafad8cdf7ea8fc26c886b3d34f81cf575ae3ea83a013b027319712a75024020d006b716927b85a71d371d97ae1c361cac6be806c631256bb626c7e8cdf8a7b0e29c9590fb47187b1ec4e508575d39a62da050b08e1a742b11883e224fa7da1deefa7477a54d99b31d2177748e1b8eb8354f3a2bdce15358f8d79cd9b17077abc3ed8f25fe084d49e05c4a9a3c0dafd576c89051337be1751be2bffb8a5ebfc9c112b34f48c662d19e32007c739817c0df4b4eb6a5916b2b3b9f8aa9215f86bc313514a3c0d5f3d66d1139ea60053c7fe9a718cb66b4b06f111a0a29f9cfcb1ed5f08b4cde0f0f9cafde3fe20a9cf9542bc12ca57d0dcb80b568ed3b244a33b215a53d349a4d9341914ce8e6a58f18b996a91f72ad06016f352f00b313a09f2ac964edbacbb70d30ee3a3524a5fb2c7e5e23c0c16fc0d8f0bb25f2519e289dc24cff22b16423d16207a1f266fb1bed803f25f5bf03afb67248d864bfb45a457d081b969283c16a7c31f487a23e4de14da214a04a32da288a0e7fe58cb490f4983b4cc66dab644a1a50ed819e79c89d983a3f2aace66aa9e9f4635bf598a06bcb4afeb4acdfbcd93bc6c615ae493810b6606a674d868fc0f512477827d4d268719ab715549908e3eaac1503fcfdfb913f3e403ca28e230f78e894a88912f0c274035a25cd385d4116dc85bfd58ef050f36ce8f77fad058fac8e0985b07f61fb985ce836b49e3811e985d6d348fbedbfd5d12991193bf148153e82562fb4e5e312cd7ab13a9a3cf8495de9cb37d6e1ae822a86f6953f96a266e9f588af73480cc198a485c5e5af30846b4a5400a08fa4d05830f4495c277d579e5bcbbb707f3dcc37b72dd006c77f80ee49cdf922c77ae7b2f4c80faa56f900d2a3fc8a7174a78968fe8b75284203716ff520bea7b432ce7801251547e816811ee014585f03ca21cc016afbf68a41c9d27cbc1602b3fa18da32dd0ea7b4383aa37366526befa1f4366413f2309b286ad7fa861db02804c24a6d18d12f65fa50cff7d50101532d326934202a76254d7691bdc19b4032a6f258d076a2472ed4ea7bf7b96741d8893d96362fd08dacdd571029ff19c9d28f0a74e643d8459f46fcfee798a74c0cac9986d79a22a4f01428883aac4dca82d6dc06ed55714449330b26eb379d497ffc237fd45c90f329cab11bd525afa29b52c755ba5bf671d94d0f10f15a6b17bebfca0637c2de833c0af7d4f2154ca9101d2f86973888a4b8cf4fc8a203b2ad064447e7e281b3e19e2c769322c80911cebb021738848be55d843a39e2db9b0e45817623bf0d7d2124875be67170d70d";
        byte[] keybytes = "WEAVER E-DESIGN.".getBytes();
        byte[] iv = "weaver e-design.".getBytes();
        String res = "";
        try {
            BufferedBlockCipher engine = new PaddedBufferedBlockCipher(
                    new CBCBlockCipher(new AESFastEngine()));
            engine.init(true, new ParametersWithIV(new KeyParameter(keybytes),iv));
            byte[] deByte = Hex.decode(content);
            engine.init(false, new ParametersWithIV(new KeyParameter(keybytes),iv));
            byte[] dec = new byte[engine.getOutputSize(deByte.length)];
            int size1 = engine.processBytes(deByte, 0, deByte.length, dec, 0);
            int size2 = engine.doFinal(dec, size1);
            byte[] decryptedContent = new byte[size1 + size2];
            System.arraycopy(dec, 0, decryptedContent, 0,
                    decryptedContent.length);
            res = new String(decryptedContent, "GBK");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        System.out.println(res);
    }
}
